using UnityEngine.UI;
using Voodoo.GameOps;
using Voodoo.Pattern;

public class BuyUpgradeButton : BuyButton
{
	public override void Fill(Item item, bool useCurrency = true, bool showLevel = false)
	{
		base.Fill(item, useCurrency, showLevel);
		if (!activeIcon.TryGetComponent<Image>(out var component))
		{
			return;
		}
		bool flag = costText.color == tooExpensiveColor;
		if (flag)
		{
			component.color = ActivityUtility.UNACTIVE;
			return;
		}
		if (!InventoryManager.Instance.HasInventory(_item))
		{
			flag = _item.ItemType != 0 || InventoryManager.Instance.CurrentlySelected(ItemType.Skin) == _item;
		}
		component.color = (flag ? ActivityUtility.UNACTIVE : ActivityUtility.ACTIVE);
	}

	public override void OnClick()
	{
		if (InventoryManager.Instance.HasInventory(_item) && _item.GetPrice(InventoryManager.Instance.GetInventoryCount(_item)) <= SingletonMB<GameManager>.Instance.PrestigePoints)
		{
			InventoryManager.Instance.SpendPrestigePoints(_item.GetPrice(InventoryManager.Instance.GetInventoryCount(_item)));
			InventoryManager.Instance.UnlockItem(_item);
			OnClicked?.Invoke();
			SingletonMB<UpgradesContainer>.Instance.Refresh();
		}
		if (InventoryManager.Instance.IsUnlocked(_item))
		{
			SingletonMB<UpgradesContainer>.Instance.Refresh();
		}
	}
}
